package com.telefonica.bmws.ws;

import java.sql.SQLException;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;

import org.apache.log4j.Logger;

import com.telefonica.bmws.dao.DesafiliaAbonadoDAO;
import com.telefonica.bmws.parameter.DesafiliaAbonadoParameter;
import com.telefonica.bmws.result.DesafiliaAbonadoResult;

@WebService(portName = "DesafiliaAbonadoWsPort",serviceName="DesafiliaAbonadoWs",targetNamespace="http://com.telefonica.bmws.ws",endpointInterface="com.telefonica.bmws.ws.DesafiliaAbonadoWs")
public class DesafiliaAbonadoWsImpl implements DesafiliaAbonadoWs {

	protected static Logger logger = Logger.getLogger("DesafiliaAbonadoWsImpl");
	@Resource
	WebServiceContext wsContext;
	
	
	@Override
	@WebMethod
	public String DesafiliarAbonado(String arg0 , String arg1) throws SQLException {
		
		MessageContext jaxwsContext =  wsContext.getMessageContext();
		HttpServletRequest request = (HttpServletRequest) jaxwsContext.get(SOAPMessageContext.SERVLET_REQUEST);
		String ipAddress = request.getRemoteAddr();
		logger.debug("Client IP consume --> " + ipAddress);
		DesafiliaAbonadoDAO dao = new DesafiliaAbonadoDAO();
		DesafiliaAbonadoResult result = new DesafiliaAbonadoResult();
		DesafiliaAbonadoParameter parameter = new DesafiliaAbonadoParameter();
		parameter.CodigoEntidad = arg1;
		parameter.NumeroCelular = arg0;
		parameter.IpCliente = ipAddress;
		result = dao.DesafiliarAbonado(parameter);

		return result.Resultado + "|" + result.Mensaje;
	}

   

}
